import { registerMicroApps, runAfterFirstMounted, setDefaultMountApp, start, initGlobalState } from 'qiankun'
const loader = (loading: boolean) => {
  console.log('loading', loading)
}

const apps =   [
  //name: 微应用的名称,
  //entry: 微应用的入口,
  //container: 微应用的容器节点的选择器或者 Element 实例,
  //activeRule: 激活微应用的规则(可以匹配到微应用的路由),
  //loader: 加载微应用的状态 true | false
  {
    name: 'vue3-1',
    entry: 'http://localhost:5174',
    container: '#container',
    activeRule: '/c1',
    loader
  },
  // {
  //   name: 'vue3-2',
  //   entry: 'http://localhost:5175',
  //   container: '#container',
  //   activeRule: '/c2',
  //   loader
  // }
]

registerMicroApps(apps,
  {
    beforeLoad: [
        (app) => {
            console.log('[LifeCycle] before load %c%s', 'color: green;', app.name)
          }
    ],
    beforeMount: [
      (app) => {
        console.log('[LifeCycle] before 挂载 %c%s', 'color: green;', app.name)
        // 主应用给子应用传参
        initGlobalState({
          data:{
             name: app.name,
             status: 'open',
             routername: ''
          }
        })
      }
    ],
    afterUnmount: [
      app => {
        console.log('[LifeCycle] after 卸载 %c%s', 'color: green;', app.name)
      }
    ]
  }
)

/**
 * Step3 设置默认进入的子应用
 */
// setDefaultMountApp('/c1')

/**
 * Step4 启动应用
 */
start({
  // sandbox: { strictStyleIsolation: true }
})
// 首次加载
runAfterFirstMounted(() => {
  console.log('[MainApp] first app mounted')
})